﻿//-----------------------------------------------------------------------
// <copyright file="Copyright.cs" author="Michael Herndon">
//     Copyright (c) Michael Herndon.  All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace Amplify.Twitter
{

	using System;
	using System.Collections.Generic;
	using System.Linq;
	using System.ServiceModel.Security;
	using System.Text;

	/// <summary>
	/// Manages friendships between users by creating, destroying, and 
	/// determining if they exist. 
	/// </summary>
	public class FriendshipClient : TwitterClient<IFriendshipClient>,  IFriendshipClient 
	{
		#region IFriendshipClient Members

		/// <summary>
		/// Initializes a new instance of the <see cref="FriendshipClient"/> class.
		/// </summary>
		/// <param name="username">The username.</param>
		/// <param name="password">The password.</param>
		public FriendshipClient(string username, string password)
			: base(username, password)
		{
			
		}

		/// <summary>
		/// Creates a friendship with the current user and the user specified.
		/// </summary>
		/// <param name="id">The screen name or user id.</param>
		/// <returns>returns a <see cref="Amplify.Twitter.User"/> object. </returns>
		/// <exception cref="System.ServiceModel.Security.MessageSecurityException" />
		/// <exception cref="Amplify.Twitter.TwitterException"> Throws when a twitter error occurs. </exception>
		public User Create(string id)
		{
			try
			{
				return this.Proxy.Create(id);
			}
			catch (MessageSecurityException securityException)
			{
				this.Rescue(securityException);
			}
			return null;
		}

		/// <summary>
		/// Destroys a friendship with the current user and the user specified.
		/// </summary>
		/// <param name="id">The screen name or user id.</param>
		/// <returns>returns a <see cref="Amplify.Twitter.User"/> object.</returns>
		/// <exception cref="System.ServiceModel.Security.MessageSecurityException" />
		/// <exception cref="Amplify.Twitter.TwitterException"> Throws when a twitter error occurs. </exception>
		public User Destroy(string id)
		{
			try 
			{
				return this.Proxy.Destroy(id);
			}
			catch (MessageSecurityException securityException)
			{
				this.Rescue(securityException);
			}
			return null;
		}

		/// <summary>
		/// Determines if their is a friendship between two users.
		/// </summary>
		/// <param name="userId1">The screen name or user id of the first user.</param>
		/// <param name="userId2">The screen name or user id of the second user.</param>
		/// <returns>returns a <see cref="Amplify.Twitter.ExistResponse"/> object.</returns>
		/// <exception cref="System.ServiceModel.Security.MessageSecurityException" />
		/// <exception cref="Amplify.Twitter.TwitterException"> Throws when a twitter error occurs. </exception>
		public ExistResponse DetermineIfExists(string userId1, string userId2)
		{
			try 
			{
				return this.Proxy.DetermineIfExists(userId1, userId2);
			}
			catch (MessageSecurityException securityException)
			{
				this.Rescue(securityException);
			}
			return null;
		}

		#endregion
	}
}
